<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
include('includes.php');
/**
 * Description of CSSParser
 *
 * @author jnankin
 */
class CSSParser {
    
    private $data = array();

    const SELECTOR_BLOCK_REGEX = "/\s*([.#a-zA-Z][\[\]'=\",#.:-\w\s]*?)\{(.*?)\}/";
    const COMMENT_REGEX = '/\/\*[\s\S]*?\*\//';
    const IMPORT_REGEX = '/@import[ \t\S]*?;/';

    public function  __construct($css) {
        $data = $this->parse($css);
    }

    public function parse($css){
        $css = $this->stripCommentsAndNewlines($css);
        $css = $this->stripImports($css);

        $blocks = $this->parseSelectorBlocks($css);

        //for each selector block, create a new selectorBlock object by passing in the selector string and the styles
        for($i = 0; $i < count($blocks[0]); $i++){
            $selectorBlock = new SelectorBlock($blocks[1][$i], $blocks[2][$i]);
        }
    }

    public function parseSelectorBlocks($css)
    {
        $blocks = array();
        preg_match_all(self::SELECTOR_BLOCK_REGEX, $css, $blocks);
        return $blocks;

    }

    public function stripCommentsAndNewlines($css){
        $css = preg_replace(self::COMMENT_REGEX, '', $css);
        $css = preg_replace('/\s+/', ' ', $css);
        return $css;
    }

    public function stripImports($css){
        return preg_replace(self::IMPORT_REGEX, '', $css);
        
    }




}
?>
